package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Custurn;
import cn.wolfcode.crm.query.impl.CusturnQuery;
import cn.wolfcode.crm.service.ICusturnService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("custurn")
public class CusturnController {
    @Autowired
    ICusturnService custurnService;

    @RequestMapping("view")
    public String view() {
        return "custurn";
    }

    @RequestMapping("getAll")
    @ResponseBody
    public List<Custurn> getAll() {
        return custurnService.selectAll();
    }

    @RequestMapping("save")
    @ResponseBody
    public JSONResult saveOrUpdate(Custurn custurn) {
        try {
                custurnService.save(custurn);
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult(false, "列表更新失败");
        }
        return new JSONResult(true, "恭喜您执行成功");
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(CusturnQuery qo) {
        return custurnService.query(qo);
    }
}
